package com.college.heyuhua.service.impl;

import com.college.heyuhua.dao.FileMapper;
import com.college.heyuhua.entity.UserInfo;
import com.college.heyuhua.model.BBSInfo;
import com.college.heyuhua.model.FileModel;
import com.college.heyuhua.service.IFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.List;

/**
 * Created by 赵东坡 on 2019/1/27.
 * Time:18:48
 * 宇宙无敌赵牛逼，祈求永无bug
 */
@Service
public class FileServiceImpl implements IFileService{


    @Autowired
    private FileMapper fileMapper;

    @Override
    public List<FileModel> getFileModelList() {
        List<FileModel> fileModels = fileMapper.getFileModelList();
        return fileModels;
    }

    @Override
    public FileModel getFileMode() {
        int max = fileMapper.getFileModeMax();
        int min = fileMapper.getFileModeMin();
        List<FileModel> list = getFileModelList();
        int temp = (int)(1+Math.random()*(max-min+1))-1;
        FileModel fileModel = new FileModel();
        int i = 0;
        while(true){
            i++;
           if(list.get(temp) != null) {
               fileModel = list.get(temp);
               break;
           }
           if(i == 100) {
               break;
           }
        }
        return fileModel;
    }

    @Override
    public UserInfo getUserInfo(long uid) {
        return fileMapper.getUserInfo(uid);
    }

    @Override
    public List<BBSInfo> getBBSListForFile(int fid, String filebbs) {
        return fileMapper.getBBSListForFile(fid,"filebbs");
    }

    @Override
    public boolean submitbbs(String bbscontent, String fid, String uid) {
        return fileMapper.submitbbs(bbscontent,fid,uid,"filebbs");
    }

    @Override
    public boolean insertfileshard(FileModel shardinfo) {
        return fileMapper.insertfileshard(shardinfo);
    }

    @Override
    public FileModel searchFile(String filename) {
        return fileMapper.searchFile(filename);
    }
}
